package org.budo.compress.tar.gz;

import java.io.File;
import java.io.FileOutputStream;
import java.util.zip.GZIPOutputStream;

import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.budo.compress.tar.TarCompressor;

/**
 * @author lmw
 */
public class TarGzipCompressor extends TarCompressor {
    @Override
    public void compress(File dir, File to) {
        try {
            String parentPath = "";

            TarArchiveOutputStream tarTo = new TarArchiveOutputStream(new GZIPOutputStream(new FileOutputStream(to)));
            tarTo.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
            this._tar(dir, tarTo, parentPath);

            tarTo.close(); // 手动关闭
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }
}
